Clover coverage report - Flock Flock - 0.7-dev
Coverage timestamp: Thu Jan 30 2003 01:35:37 EST
file stats: LOC: 94   Methods: 3
NCLOC: 64   Classes: 1
This license of Clover is provided to support the development of Flock only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
FlockServlet.java 0% 0% 0% 0%
 1   
 package net.sf.flock.webapp;
 2   
 
 3   
 import java.io.IOException;
 4   
 import java.io.OutputStreamWriter;
 5   
 import java.io.PrintWriter;
 6   
 import java.util.Collection;
 7   
 
 8   
 import javax.servlet.ServletConfig;
 9   
 import javax.servlet.ServletContext;
 10   
 import javax.servlet.ServletException;
 11   
 import javax.servlet.http.HttpServlet;
 12   
 import javax.servlet.http.HttpServletRequest;
 13   
 import javax.servlet.http.HttpServletResponse;
 14   
 
 15   
 import net.sf.flock.FilterI;
 16   
 import net.sf.flock.FlockResourceException;
 17   
 import net.sf.flock.SubscriptionManagerI;
 18   
 import net.sf.flock.filter.Limit;
 19   
 import net.sf.flock.filter.MetaStartsWith;
 20   
 import net.sf.flock.filter.SortByDate;
 21   
 import net.sf.flock.support.Rss091Export;
 22   
 import net.sf.flock.support.StylesheetExportFilter;
 23   
 
 24   
 import org.jdom.Document;
 25   
 import org.jdom.output.XMLOutputter;
 26   
 
 27   
 /**
 28   
  * @version $Revision: 1.19 $
 29   
  * @author $Author: phraktle $
 30   
  */
 31   
 public class FlockServlet extends HttpServlet {
 32   
 
 33   
     private final static int MAX_ARTICLES = 20;
 34   
 
 35   
     private String defaultStylesheet;
 36   
 
 37  0
     public void init(ServletConfig config) throws ServletException {
 38  0
         super.init(config);
 39   
     
 40  0
         this.defaultStylesheet = config.getInitParameter("defaultStylesheet");
 41   
     }
 42   
 
 43  0
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 44  0
         doPost(request, response);
 45   
     }
 46   
 
 47  0
     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 48   
 
 49   
         //System.out.println("pathInfo: "+request.getPathInfo());
 50   
         //System.out.println("servletPath: "+request.getServletPath());
 51  0
         String path = request.getPathInfo();
 52  0
         if (path==null) {
 53  0
             path = "/";
 54  0
         } else if (!path.startsWith("/")) {
 55  0
             path += "/";
 56   
         }
 57   
 
 58  0
         String stylesheet = request.getParameter("stylesheet");
 59  0
         if (stylesheet==null) {
 60  0
             stylesheet = this.defaultStylesheet;
 61   
         }
 62   
 
 63   
         //stylesheet = request.getContextPath() + '/' + stylesheet;
 64   
             
 65  0
         ServletContext ctx = this.getServletContext();
 66  0
         FlockContext.setSubscriptionManager( (SubscriptionManagerI) ctx.getAttribute("flock.subscriptionManager") );
 67   
 
 68  0
         Collection aggregate;
 69  0
         try {
 70   
 
 71  0
             aggregate = FlockContext.getSubscriptionManager().findItems( new FilterI[] {
 72   
                 new MetaStartsWith("path", path), 
 73   
                 new SortByDate(),
 74   
                 new Limit(MAX_ARTICLES),
 75   
             });
 76   
 
 77   
         } catch (FlockResourceException e) {
 78  0
             throw new ServletException(e);
 79   
         }
 80  0
         if (aggregate==null) {
 81  0
             response.sendError(HttpServletResponse.SC_NOT_FOUND);
 82   
         }
 83   
 
 84  0
         Document doc = new StylesheetExportFilter( stylesheet ).filter( new Rss091Export().export(path, aggregate) );
 85   
 
 86  0
         response.setContentType("text/xml; charset=UTF-8");
 87  0
         XMLOutputter outputter = new XMLOutputter("  ", true);
 88   
 
 89  0
         PrintWriter out = new PrintWriter( new OutputStreamWriter(response.getOutputStream(), "UTF8"), true );
 90  0
         outputter.output(doc, out);
 91   
     }
 92   
 
 93   
 }
 94